package com.example.demo.entity;

import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;

@Data
@Entity
public class Taco {
    @NotNull
    @Size(min = 5, message = "Name must be at least 5 characters log")
    private String name;


    @ManyToMany(targetEntity = Ingredient.class) //每个Taco可以有多个ingredient，每个ingredient组成多个taco 多对多关系
    @Size(min = 1, message = "must be choose at least 1 ingredient")
    private List<Ingredient> ingredients;


    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;


    private Date createAt;

    @PrePersist
        //在持久化之前，使用这个方法将时间设置为当前时间
    void createdAt() {
        this.createAt = new Date();
    }
}
